package com.xbongbong.paas.service.workflow.trigger;

import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.FilterConditionsPoJo;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataDeleteBatchDTO;
import com.xbongbong.paas.pojo.dto.FormDataUpdateBatchDTO;
import com.xbongbong.paas.pojo.dto.FormDataUpdateDTO;
import com.xbongbong.paas.pojo.vo.FormDataAddVO;
import com.xbongbong.paas.pojo.vo.FormDataUpdateVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.pro.businessrule.pojo.BusinessRuleInfoPojo;
import com.xbongbong.pro.formdata.pojo.vo.BeforeSaveVO;
import com.xbongbong.pro.formdata.pojo.vo.BeforeUpdateVO;
import com.xbongbong.pro.workflow.enums.WorkflowOperateEnum;
import com.xbongbong.workflow.domain.entity.WorkflowEntity;

import java.util.List;
import java.util.Map;

/**
 * @author chenpeng
 * @version 1.0
 * @date 2021-05-13 19:29
 * @description
 */
public interface WorkflowFormDataOperationService {
    
    /**
     * 这里返回多个符合触发的工作流
     * @param corpid
     * @param formId
     * @param businessType
     * @param triggerType
     * @return
     * @throws XbbException
     */
    List<WorkflowEntity> getSatisfyTriggerEntitys(String corpid, Long formId, Integer businessType, List<Integer> triggerType) throws XbbException;
    /**
     * 单条新建触发工作流
     * @param formDataAddDTO
     * @param beforeSaveVO
     * @param formDataSaveVO
     * @throws XbbException
     */
    void workflowAddTrigger(FormDataAddDTO formDataAddDTO, BeforeSaveVO beforeSaveVO, FormDataAddVO formDataSaveVO) throws XbbException;
    /**
     * 单条编辑触发工作流
     * @param formDataUpdateDTO
     * @param beforeSaveVO
     * @param formDataSaveVO
     * @throws XbbException
     */
    void workflowUpdateTrigger(FormDataUpdateDTO formDataUpdateDTO, BeforeUpdateVO beforeSaveVO, FormDataUpdateVO formDataSaveVO) throws XbbException;

    /**
     * 批量编辑触发工作流
     * @param formDataUpdateBatchDTO
     * @param oldDataList
     * @return void
     * @author 吴峰
     * @date 2021/7/6 13:54
     * @throws XbbException
     */
    void workflowUpdateBatchTrigger(FormDataUpdateBatchDTO formDataUpdateBatchDTO, List<PaasFormDataEntityExt> oldDataList) throws XbbException;

    /**
     * 删除触发工作流
     * @param formDataDeleteBatchDTO
     * @param deleteIds
     * @param workflowOperateEnum
     * @throws XbbException
     */
    void workflowDeleteTrigger(FormDataDeleteBatchDTO formDataDeleteBatchDTO, List<Long> deleteIds, WorkflowOperateEnum workflowOperateEnum) throws XbbException;
    /**
     * 校验触发条件是否匹配
     * @param preConditionList
     * @param thisFormData
     * @param businessRuleInfoPojo
     * @return false : 不可执行当前这条工作流； true：可以执行
     * @throws XbbException
     */
    boolean validatePreCondition(List<FilterConditionsPoJo> preConditionList, PaasFormDataEntity thisFormData, BusinessRuleInfoPojo businessRuleInfoPojo) throws XbbException;

    /**
     * 数据是否可编辑
     * @param formId
     * @param corpid
     * @param saasMark
     * @param businessType
     * @param flowStatus
     * @param userVO
     * @return
     */
    boolean isApprovedEdit(Long formId, String corpid, Integer saasMark, Integer businessType, Integer flowStatus, UserVO userVO);


    /**
     * 审批流和工作流判断数据是否可编辑
     * @param fromCopy
     * @param appId
     * @param menuId
     * @param formId
     * @param corpid
     * @param saasMark
     * @param businessType
     * @param flowStatus
     * @param userVO
     * @return
     * @throws XbbException
     */
    void isApprovedEdit(boolean fromCopy, Long appId, Long menuId, Long formId, String corpid, Integer saasMark, Integer businessType, Integer flowStatus, UserVO userVO) throws XbbException;



    /**
     * 是否启用新工作流
     * 且判断是否符合触发类型
     * @param formDataSaveDTO
     * @param beforeSaveVO
     * @param paasFormDataEntity
     * @return
     * @throws XbbException
     */
    boolean isEnableNewWorkflow(FormDataAddDTO formDataSaveDTO, BeforeSaveVO beforeSaveVO, PaasFormDataEntity paasFormDataEntity) throws XbbException;

    /**
     * 是否启用工作流
     * 且判断是否符合触发类型
     * @param formDataUpdateDTO
     * @param explainMap
     * @param oldPaasFormData
     * @param paasFormDataEntity
     * @return
     * @throws XbbException
     */
    boolean isEnableNewWorkflow(FormDataUpdateDTO formDataUpdateDTO, Map<String, FieldAttrEntity> explainMap, PaasFormDataEntity paasFormDataEntity, PaasFormDataEntity oldPaasFormData) throws XbbException;

    /**
     * 是否启用新工作流
     * 且判断是否符合触发类型
     * @param formDataDeleteBatchDTO
     * @return
     * @throws XbbException
     */
    boolean isEnableNewWorkflow(FormDataDeleteBatchDTO formDataDeleteBatchDTO, List<Long> deleteIds, WorkflowOperateEnum workflowOperateEnum) throws XbbException;

    /**
     * 执行自定义工作流
     * @param paasFormDataEntity
     * @param explainMap
     * @param userVO
     * @param subBusinessType
     * @param workflowId
     * @param corpid
     * @throws XbbException
     */
    void executeWorkflow(PaasFormDataEntity paasFormDataEntity, Map<String, FieldAttrEntity> explainMap, UserVO userVO, Integer subBusinessType, Long workflowId, String corpid) throws XbbException;
}
